package com.sunny.service;

import com.sunny.dataobject.ProductCategory;
import com.sunny.repository.ProductCategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * Created by dell on 2018/3/29.
 */
@Service
public class CategoryServiceImpl implements  CategoryService {
    @Autowired
    private ProductCategoryRepository repository;

    public ProductCategory findOne(Integer id) {
        ProductCategory productCategory=new ProductCategory();
        productCategory.setCategoryId(id);
        Example<ProductCategory> example=Example.of(productCategory);
        Optional<ProductCategory> res = repository.findOne(example);
        return res.get();
    }

    public List<ProductCategory> findAll() {
        return repository.findAll();
    }

    public List<ProductCategory> findByCataegoryTypeIn(List<Integer> cataegoryTypeIn) {
        return repository.findByCategoryTypeIn(cataegoryTypeIn);
    }

    public ProductCategory save(ProductCategory productCategory) {
        return repository.save(productCategory);
    }
}
